package shape;

/**
 * @author Zach Turk
 * @author Ken "David" McClain
 */

import javax.media.opengl.*;

import main.SceneGraphNode;
import physics.*;

public class Circle extends PhysicsObject {
	/** Serial ID */
	private static final long serialVersionUID = -7470170470492823281L;

	public class Renderable extends SceneGraphNode {
		/** Serial ID */
		private static final long serialVersionUID = 8483230612621632334L;

		public Renderable() {
			super(true);
			scale = radius;
		}
		
		public Renderable(boolean pickable) {
			super(pickable);
			scale = radius;
		}
		
		public void renderGeometry(GLAutoDrawable drawable) {
			GL2 gl = drawable.getGL().getGL2();
			gl.glBegin(GL.GL_TRIANGLE_FAN);
			
			gl.glColor3f(0, 0.5f, 1.5f);
			gl.glVertex2f(0, 0);
			gl.glColor3f(red, green, blue);
			//the denominator in Math.PI/30 is the number of sides the circle will have
			//for some reason, this number needs to be a multiple of 3 to get a full circle
			double step = 2*Math.PI/30;
			for (float i = 0; i < 2*Math.PI; i += step) {
				gl.glVertex2d(Math.cos(i), Math.sin(i));
			}
			gl.glEnd();
		}
	}
	
	public float radius;
	float red;
	float green;
	float blue;
	
	public Circle(float rad) {
		this(rad, (float)Math.random(), (float)Math.random(), (float)Math.random());
	}
	
	public Circle(float rad, float red, float green, float blue) {
		inverseMomentOfInertia = 1 / (float)(Math.PI * Math.pow(rad, 4) / 4);
		this.radius = rad;
		this.red = red;
		this.green = green;
		this.blue = blue;
		renderable = new Renderable();
	}
	
	public void setSize(float rad) {
		this.radius = rad;
	}
}